package cn.minhx.domain.crowd.service;

import cn.minhx.domain.crowd.adapter.repository.ICrowdRepository;
import cn.minhx.domain.crowd.model.entity.CrowdTagsJobEntity;
import jakarta.annotation.Resource;
import java.util.Set;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * 人群标签服务
 *
 * @author min
 */
@Slf4j
@Service
public class CrowdServiceImpl implements ICrowdService {

	@Resource
	private ICrowdRepository repository;

	@Override
	public void execTagBatchJob(String tagId, String batchId) {
		log.info("人群标签批次任务 tagId:{},batchId:{}", tagId, batchId);
		// 1. 查询批次任务
		CrowdTagsJobEntity crowdTagsJobEntity = repository.queryCrowdTagsJobEntity(tagId, batchId);
		// 2. 采集用户数据 - 需要采集用户的消费类数据，后续有用户发起拼单后再处理
		// todo
		// 3. 数据写入记录）
		Set<String> userIdSet = Set.of("user001", "user002", "user003", "user004", "user005");
		for (String userId : userIdSet) {
			repository.addCrowdTagsUserId(tagId, userId);
		}
		// 4. 更新人群标签统计量
		repository.updateCrowdTagsStatistics(tagId, userIdSet.size());
	}
}
